{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from gs_quant.instrument import IRFixedLeg, IRFloatLeg, IRSwap\n",
    "from gs_quant.markets import PricingContext\n",
    "from gs_quant.session import GsSession"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "# external users should substitute their client id and secret\n",
    "GsSession.use(client_id=None, client_secret=None, scopes=('run_analytics',))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "tags": [
     "Instrument - IRFixedLeg",
     "Instrument - IRFloatLeg"
    ]
   },
   "outputs": [],
   "source": [
    "fixed_leg = IRFixedLeg('Buy', fixed_rate=0.05, notional_currency='USD', termination_date='5y', notional_amount=100e6)\n",
    "\n",
    "float_leg = IRFloatLeg(\n",
    "    'Sell', notional_currency='USD', termination_date='5y', floating_rate_spread=40 / 1e4, notional_amount=100e6\n",
    ")\n",
    "\n",
    "swap = IRSwap(\n",
    "    pay_or_receive='Receive',\n",
    "    termination_date='5y',\n",
    "    notional_currency='USD',\n",
    "    fixed_rate=0.05,\n",
    "    floating_rate_spread=40 / 1e4,\n",
    "    principal_exchange='None',\n",
    "    notional_amount=100e6,\n",
    ")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "tags": [
     "CSA"
    ]
   },
   "outputs": [],
   "source": [
    "with PricingContext(csa_term='USD-SOFR'):\n",
    "    fixed_price = fixed_leg.price()\n",
    "    float_price = float_leg.price()\n",
    "    swap_price = swap.price()\n",
    "\n",
    "print(fixed_price.result() + float_price.result())\n",
    "print(swap_price.result())"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.11.5"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 4
}
